plinstrument:
{
calc:"
// Blinder 2x100 RGBW 12ch (based on LED Blinder RGBW)

#include	colorconv
#include	hsv
#include	ledref
#include	strobe


// controls
cDim; cSht; cFnc; cFns; cPix;

// parameters

// constants
kDia = 0.11;
kWid = 0.32;
kHi = 0.15;
kZBack = 0.07;
kZFront = -0.07;

kPit = 0.16;
kPixs = 2;

kCnt  = 2;						// (?)
kSpd  = Spread(kCnt, 0.1, 70);	// (field angle?)
kSpdH = kSpd;
kSpdV = kSpd;

kSource = LEDRefConv(100, kDia, kLEDRefWatt_RGBW, kLEDRefDia_RGBW, kLEDRefSrc_RGBW);
kWhite = kLEDRefWhite_RGBW;


// protocol parameters
LIGHT;
SHAPE;
SIMPLE;

PRM=1;
CTL;


// dimmer

gDimmer;

DimmerTime#
(
	gDimmer = cDim / 255;
);


// shutter

kStrobeMin = 1;			// [Hz]
kStrobeMax = 20;		// [Hz] (?)
kStrobeDur = 1 / 30;	// [s] (?)

gShutter;
gStrobe[0];

ShutterTime#
(
	(cSht < 2)?	// open (?)
	(
		gShutter = 1;
	)
	:			// strobe
	(
		ss = ParamSqr(kStrobeMin, kStrobeMax, 2, 255, cSht);
		StrobeProgress(gStrobe, $0 * ss, kStrobeDur * ss);
		gShutter = gStrobe.ef;
	);
);


// color
kColorSpeedMax = 167 / 60;		// [1/s] (?) (of Alpha Spot HPE 300)
kColorSpeedMin = 0.2 / 60;		// [1/s] (?) (of Alpha Spot HPE 300)

gPix;	// rgbw[kPixs]
gColorPh;


PixColor#	// (pix) color
(
	p = cPix[$0];
	Vec(p.cR / 255, p.cG / 255, p.cB / 255, p.cW / 255)
);


PixAll#		// (color)
(
	@(i < kPixs)
	(
		gPix[i] = $0;
		++i;
	);
);


ColorTime#
(
	(cFnc < 51)?	// dim
	(
		@(i < kPixs)
		(
			gPix[i] = PixColor(i);
			++i;
		);
	)
	:(cFnc < 101)?	// sel (hue?)
	(
		h = floor(12 * cFns / 256) / 12;	// 12 colors (?)
		c = RGBfromHSV(h, 1, 1);
		PixAll(c);
	)
	:(cFnc < 151)?	// jump (hue?)
	(
		cs = ParamSqr(kColorSpeedMin, kColorSpeedMax, 0, 255, cFns);
		gColorPh = Cycle(gColorPh + $0 * cs);
		h = floor(12 * gColorPh) / 12;	// 12 colors (?)
		c = RGBfromHSV(h, 1, 1);
		PixAll(c);
	)
	:(cFnc < 201)?	// gradient (hue?)
	(
		cs = ParamSqr(kColorSpeedMin, kColorSpeedMax, 0, 255, cFns);
		gColorPh = Cycle(gColorPh + $0 * cs);
		h = gColorPh;
		c = RGBfromHSV(h, 1, 1);
		PixAll(c);
	)
	:(cFnc < 250)?	// pulse (hue?)
	(
		cs = ParamSqr(kColorSpeedMin, kColorSpeedMax, 0, 255, cFns);
		gColorPh = Cycle(gColorPh + $0 * cs * 0.5);
		h = 2 * ((gColorPh < 0.5)? gColorPh : (1 - gColorPh));
		c = RGBfromHSV(h, 1, 1);
		PixAll(c);
	)
	:	// sound (no support)
	(
		c = Vec(1, 1, 1, 1);
		PixAll(c);
	);
);


// protocol methods

UPDATE#
(
	DimmerTime($0);
	ShutterTime($0);
	ColorTime($0);

	PRM?
	(
		// shape
		hw = kWid * 0.5;
		hh = kHi * 0.5;
		SHAPE = Box(-hw, hw, -hh, hh, kZBack, kZFront);
			
		x = -(kPixs - 1) * 0.5 * kPit;
		@(i < kPixs)
		(
			l = LIGHT[i];
			l.pos[0] = x;
			l.pos[2] = kZFront;
			l.dia = kDia;
			l.spdh = kSpdH;
			l.spdv = kSpdV;
			l.cnt = kCnt;
			LIGHT[i] = l;
			x += kPit;
			++i;
		);

		// simplified
		sd = SIMPLE[0];
		sd.pos[2] = kZFront;
		sd.dia = kDia;
		sd.spdh = kSpdH;
		sd.spdv = kSpdV;
		sd.cnt = kCnt;
		sd.filh = kPit * (kPixs - 1);
		sd.slv = SimpleOverlap(kPit, kSpdH);
		sd.ssn = kPixs;
		SIMPLE[0] = sd;
	);

//	(PRM | CTL)?
	(
		d = kSource * gDimmer * gShutter;
		i = 0;
		@(i < kPixs)
		(
			c = gPix[i];
			c = RGBfromRGBW(c, kWhite);
			c = VecScale(c, d);
			LIGHT[i].color = c;
			sc = VecAdd(sc, c);
			++i;
		);

		// simplified
		sd = SIMPLE[0];
		sd.color = VecScale(sc, 1 / kPixs);
		SIMPLE[0] = sd;
	);

	PRM = CTL = 0;
);

";


chmap:"cDim cSht cFnc cFns cPix(cR cG cB cW)[2]";


ctl:
{
	controls:
	{
		type:numeric;
		id:cDim;
		name:Dimmer;
		max:255;
		ini:255;
	},
	{
		type:numeric;
		id:cSht;
		name:Shutter;
		max:255;
	},
	{
		type:numeric;
		id:cFnc;
		name:Function;
		max:255;
	},
	{
		type:numeric;
		id:cFns;
		name:Speed;
		max:255;
	},
	{
		type:array;
		id:cPixs;
		label:Pixel;
		elemid:cPix;
		base:1;
		
		fixed:1;
		max:2;
		ini:2;

		controls:
		{
			type:numeric;
			id:cR;
			name:R;
			max:255;
			ini:255;
		},
		{
			type:numeric;
			id:cG;
			name:G;
			max:255;
			ini:255;
		},
		{
			type:numeric;
			id:cB;
			name:B;
			max:255;
			ini:255;
		},
		{
			type:numeric;
			id:cW;
			name:W;
			max:255;
			ini:255;
		};
	};
};


prm:
{
	controls:
	{
	};
};


};
